package com.fanketly.funacg2.ui.screen

import android.content.res.Configuration
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.NetworkCheck
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.fanketly.funacg2.App
import com.fanketly.funacg2.R
import com.fanketly.funacg2.ui.components.ActionRowCard
import com.fanketly.funacg2.ui.theme.FunACG2Theme
import com.fanketly.funacg2.ui.viewmodels.SettingViewModel
import com.fanketly.funacg2.utils.ToastUtils
import com.fanketly.funacg2.utils.getAppString
import com.ramcosta.composedestinations.annotation.Destination

@Destination
@Composable
fun Setting(settingViewModel: SettingViewModel = hiltViewModel()) {
    SettingContent(getBestServer = {
        ToastUtils.shortToast(getAppString(R.string.get_best_server))
        settingViewModel.getBestServer()
    })
}

@Composable
private fun SettingContent(getBestServer: () -> Unit) {
    Column(Modifier.fillMaxSize()) {
        ActionRowCard(
            modifier = Modifier.padding(4.dp),
            rowModifier = Modifier.padding(8.dp),
            imageVector = Icons.Filled.NetworkCheck,
            text = stringResource(id = R.string.get_server),
            onClick = getBestServer
        )
    }
}

@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(showBackground = true)
@Composable
private fun DefaultPreview() {
    FunACG2Theme {
        SettingContent(getBestServer = {})
    }
}